home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / RCS / Histogram.cc,v < prev    next >
Text File  |  1989-05-04  |  3KB  |  176 lines

  1. head     3.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    grunwald:3.3; strict;
  6. comment  @@;
  7.  
  8.  
  9. 3.3
  10. date     89.05.04.15.00.03;  author grunwald;  state Exp;
  11. branches ;
  12. next     3.2;
  13.  
  14. 3.2
  15. date     89.02.20.15.35.01;  author grunwald;  state Exp;
  16. branches ;
  17. next     3.1;
  18.  
  19. 3.1
  20. date     88.12.20.13.48.52;  author grunwald;  state Exp;
  21. branches ;
  22. next     1.2;
  23.  
  24. 1.2
  25. date     88.10.30.13.03.11;  author grunwald;  state Exp;
  26. branches ;
  27. next     1.1;
  28.  
  29. 1.1
  30. date     88.09.18.16.42.25;  author grunwald;  state Exp;
  31. branches ;
  32. next     ;
  33.  
  34.  
  35. desc
  36. @@
  37.  
  38.  
  39. 3.3
  40. log
  41. @ Before switching to Libg++ version
  42. @
  43. text
  44. @// This may look like C code, but it is really -*- C++ -*-
  45. // 
  46. // Copyright (C) 1988 University of Illinois, Urbana, Illinois
  47. //
  48. // written by Dirk Grunwald (grunwald@@cs.uiuc.edu)
  49. //
  50. #include "Histogram.h"
  51. #include <math.h>
  52.  
  53. const int HistogramMinimum = -2;
  54. const int HistogramMaximum = -1;
  55.  
  56. Histogram::Histogram(double low, double high, double width)
  57. {
  58.     if (high < low) {
  59.     double t = high;
  60.     high = low;
  61.     low = t;
  62.     }
  63.  
  64.     if (width == -1) {
  65.     width = (high - low) / 10;
  66.     }
  67.  
  68.     howManyBuckets = int((high - low) / width) + 2;
  69.     bucketCount = new int[howManyBuckets];
  70.     bucketLimit = new double[howManyBuckets];
  71.     double lim = low;
  72.     for (int i = 0; i < howManyBuckets; i++) {
  73.     bucketCount[i] = 0;
  74.     bucketLimit[i] = lim;
  75.     lim += width;
  76.     }
  77.     bucketLimit[howManyBuckets-1] = MAXFLOAT;    /* from math.h */
  78. }
  79.  
  80. Histogram::~Histogram()
  81. {
  82.     if (howManyBuckets > 0) {
  83.     delete bucketCount;
  84.     delete bucketLimit;
  85.     }
  86. }
  87.  
  88. void
  89. Histogram::operator+=(double value)
  90. {
  91.     int i;
  92.     for (i = 0; i < howManyBuckets; i++) {
  93.     if (value < bucketLimit[i]) break;
  94.     }
  95.     bucketCount[i]++;
  96.     Statistic::operator+=(value);
  97. }
  98.  
  99. int
  100. Histogram::similarSamples(double d)
  101. {
  102.     int i;
  103.     for (i = 0; i < howManyBuckets; i++) {
  104.     if (d < bucketLimit[i]) return(bucketCount[i]);
  105.     }
  106.     return(0);
  107. }
  108.  
  109. void
  110. Histogram::classPrintOn(ostream& s)
  111. {
  112.     Statistic::classPrintOn(s);
  113.     s << "\n";
  114.     for(int i = 0; i < howManyBuckets; i++) {
  115.     s << "< " << bucketLimit[i] << " : " << bucketCount[i] << "\n";
  116.     }
  117. }
  118.  
  119. void
  120. Histogram::printBuckets(ostream& s)
  121. {
  122.     for(int i = 0; i < howManyBuckets; i++) {
  123.     if (bucketLimit[i] >= MAXFLOAT) {
  124.         s << "< max : " << bucketCount[i] << "\n";
  125.     } else {
  126.         s << "< " << bucketLimit[i] << " : " << bucketCount[i] << "\n";
  127.     }
  128.     }
  129. }
  130.  
  131. void
  132. Histogram::reset()
  133. {
  134.     Statistic::reset();
  135.     if (howManyBuckets > 0) {
  136.     for (register int i = 0; i < howManyBuckets; i++) {
  137.         bucketCount[i] = 0;
  138.     }
  139.     }
  140. }
  141.  
  142. @
  143.  
  144.  
  145. 3.2
  146. log
  147. @Start using Gnu library heaps for schedulers
  148. @
  149. text
  150. @@
  151.  
  152.  
  153. 3.1
  154. log
  155. @Steay version
  156. @
  157. text
  158. @@
  159.  
  160.  
  161. 1.2
  162. log
  163. @*** empty log message ***
  164. @
  165. text
  166. @@
  167.  
  168.  
  169. 1.1
  170. log
  171. @Initial revision
  172. @
  173. text
  174. @d1 6
  175. @
  176.